Ext.namespace("App.Base.Common.func");

 App.Base.Common.func.getCurrentSysTimeStamp = function () {
	var now = new Date();
	var hour = now.getHours();
	var minutes = now.getMinutes();
	var seconds = now.getSeconds();

	hour = (hour > 9) ? hour : ('0' + hour);
	minutes = (minutes > 9) ? minutes : ('0' + minutes);
	seconds = (seconds > 9) ? seconds : ('0' + seconds);

	return hour+':'+minutes+':'+seconds;
 }

trim = function(str) 
{ 
	return str.replace(/(^\s*)|(\s*$)/g, ""); 
} 

ltrim = function(str) 
{ 
return str.replace(/(^\s*)/g, ""); 
} 

rtrim = function(str) 
{ 
return str.replace(/(\s*$)/g, ""); 
} 

App.Base.Common.func.include = function(scriptName, scriptType){
    scriptName = scriptName.trim();
    scriptType = scriptType.trim();
    
    if (scriptType == 'css')
    {
        document.write('<link rel="stylesheet" type="text/css" href="' + scriptName + '" charset="utf-8"/>');
    }
    else if (scriptType == 'javascript')
    {
        document.write('<script type="text/javascript" src="' + scriptName + ' charset="utf-8"></script>');
    }
    else
    {
    }
};

App.Base.Common.func.isUndefinedOrNull = function(object){
	if (typeof(object) == 'undefined' || object == null)
	{
		return true;
	}

	return false;
};

App.Base.Common.func.isEmptyString = function(object){
	if (App.Base.Common.func.isUndefinedOrNull(object) || object.length == 0)
	{
		return true;
	}

	return false;
};

Ext.override(Ext.tree.TreeNode, {
	setIcon: function(src){
		var iel = this.getUI().getIconEl();    
		if (iel){      
			var el = Ext.get(iel);     
			if (el) {       
				el.addClass('x-tree-node-inline-icon');        
				el.dom.src = src;      
			}    
		}  
	}, 

	setIconCls: function(iconClassName) {  
		var iel = this.getUI().getIconEl();    
		if (iel) 
		{     
			var el = Ext.get(iel);   
			if (el)
			{      
				el.addClass(iconClassName);
			}  
		} 
	}
});

Ext.QuickTips.init();

//params: {title: ,msg: ,icon: }
App.Base.Common.func.MESSAGEBOX_SHOW = function(params){
	Ext.Msg.show({
	   title: params.title,
	   msg: params.msg,
	   buttons: Ext.Msg.OK,
	   //fn: processResult,
	   //animEl: 'elId',
	   icon: params.icon
	});
};

App.Base.Common.func.getSystemDateTimeMark = function(){
	var date = new Date();
	return (date.getFullYear().toString()
		+ date.getMonth().toString()
		+ date.getDate().toString()
		+ date.getHours().toString()
		+ date.getMinutes().toString()
		+ date.getSeconds().toString()
		+ date.getMilliseconds());
};

App.Base.Common.func.checkUserDefSessionStatus = function(response){
	if(!(typeof response.getResponseHeader['User-Defined-Session-Status'] == 'undefined')){   
		App.Base.Common.func.MESSAGEBOX_SHOW({
			title: App.Base.common.param.MESSAGEBOX_NORMAL_TIPS,
			msg: '用户会话超时：请刷新浏览器，重新登录',
			icon: Ext.MessageBox.ERROR
		});	
		return true;
	}

	return false;
};

App.Base.Common.func.extLibAjaxRequestComplete = function(conn,response,options){
	App.Base.Common.func.checkUserDefSessionStatus(response); 
};

App.Base.Common.func.request = function(params){
	Ext.lib.Ajax.request(
		params.method,
		params.url,
		{
			success: function(response){
				if (App.Base.Common.func.checkUserDefSessionStatus(response))
				{
					return;
				}
				params.success.call(params.scope, response);
			},
			failure: params.failure,
			scope: params.scope
		},
		params.params
	);
};

//generating the global unique id.
App.Base.Common.func.generateGlobalUniqueId = function(config, mark){
	var moduleId = (typeof(config) == 'undefined') ? null : config.id;
	moduleId = (moduleId == null) ? App.Base.Common.func.getSystemDateTimeMark() : moduleId;
	moduleId = mark + moduleId;
	return moduleId;
};